package web

import (
	"errors"
	"fmt"
	"goRss/appconfig"

	"github.com/labstack/echo"
)

func Start() error {
	if appconfig.AppConfig.WebPort == "" {
		return errors.New("web port not define")
	}

	e := echo.New()
	e.File("/", "html/index.html")
	e.Static("/html", "html")

	//e.File("/", "html/index.html")
	// e.Use(middleware.CORS())

	e.GET("/api/GetCh", GetCH)
	e.GET("/api/GetNews", GetNews)

	// e.POST("/api/SetStar", SetStar)

	fmt.Println("start web service " + appconfig.AppConfig.WebPort)
	err := e.Start(":" + appconfig.AppConfig.WebPort)
	if err != nil {
		fmt.Println(err)
		return err
	}
	return nil
}
